<%@ page import="com.cinsea.security.util.JdbcUtil" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/common/common.jsp" %>
<%
    List<Option> options = optionService.getOptions2("48f5f3ea39aec2a30139aec571670004", null);
    JdbcDao jdbcDao = Env.getBean("jdbcDao");
    List<Map> topicnums = jdbcDao.queryForList(JdbcUtil.getPermissionSql("select types,COUNT(*) as topicnum,MAX(CREATEDATETIME) as topicmaxtime from cs_topic where deleted!=1  group by types","cs_topic"));
    List<Map> replynums = jdbcDao.queryForList(JdbcUtil.getPermissionSql("select t2.types,COUNT(t1.id) as replynum,MAX(t1.CREATEDATETIME) as replymaxtime from cs_topic t2, cs_topicreply t1 where t2.deleted!=1 and t1.PROCESSID=t2.PROCESSID  group by t2.types","cs_topic"));
%>
<html>
<head>
    <%@ include file="/common/head.jsp" %>
</head>
<body>
<table width="100%">
    <colgroup>
        <col width="1%">
        <col width="98%">
        <col width="1%">
    </colgroup>
    <tr>
        <td></td>
        <td>
            <table class="formdetailtable">
                <colgroup>
                    <col width="40%">
                    <col width="20%">
                    <col width="20%">
                    <col width="20%">
                </colgroup>
                <tr>
                    <td class="headertd">栏目</td>
                    <td class="headertd">主题</td>
                    <td class="headertd">帖子</td>
                    <td class="headertd">最后发表时间</td>
                </tr>
                <%
                    for (Option option : options) {
                        int topcnum = 0;
                        int replynum = 0;
                        String maxtime = "";
                        for (Map topicnumMap : topicnums) {
                            String type = StringUtil.null2String(topicnumMap.get("types"));

                            if (type.equals(option.getId())) {
                                String numstr = String.valueOf(topicnumMap.get("topicnum"));
                                String topicmaxtime = StringUtil.null2String(topicnumMap.get("topicmaxtime"));
                                if (topicmaxtime.compareTo(maxtime) > 0) maxtime = topicmaxtime;
                                topcnum = NumberUtil.getIntegerValue(numstr);
                                break;
                            }
                        }
                        for (Map replynumMap : replynums) {
                            String type = StringUtil.null2String(replynumMap.get("types"));
                            if (type.equals(option.getId())) {
                                String numstr = String.valueOf(replynumMap.get("replynum"));
                                String replymaxtime = StringUtil.null2String(replynumMap.get("replymaxtime"));
                                if (replymaxtime.compareTo(maxtime) > 0) maxtime = replymaxtime;
                                replynum = NumberUtil.getIntegerValue(numstr);
                                break;
                            }
                        }
                %>
                <tr>
                    <td><a href="javascript:onUrl('/bbs/topiclist.jsp?directoryid=3&types=<%=option.getId()%>','<%=option.getObjname()%>')"><%=option.getObjname()%></a>
                    </td>
                    <td><%=topcnum%>
                    </td>
                    <td><%=topcnum + replynum%>
                    </td>
                    <td><%=maxtime%>
                    </td>
                </tr>
                <%}%>
            </table>
        </td>
        <td></td>
    </tr>
</table>
</body>
</html>